package com.yaorange.teaching.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yaorange.common.log.annotation.Log;
import com.yaorange.common.log.enums.BusinessType;
import com.yaorange.common.security.annotation.RequiresPermissions;
import com.yaorange.teaching.domain.YaCourseDesign;
import com.yaorange.teaching.service.IYaCourseDesignService;
import com.yaorange.common.core.web.controller.BaseController;
import com.yaorange.common.core.web.domain.AjaxResult;
import com.yaorange.common.core.utils.poi.ExcelUtil;
import com.yaorange.common.core.web.page.TableDataInfo;

/**
 * 课程设计Controller
 *
 * @author ruoyi
 * @date 2024-11-16
 */
@RestController
@RequestMapping("/course_design")
public class YaCourseDesignController extends BaseController
{
    @Autowired
    private IYaCourseDesignService yaCourseDesignService;

    /**
     * 查询课程设计列表
     */
    @RequiresPermissions("teaching:course_design:list")
    @GetMapping("/list")
    public TableDataInfo list(YaCourseDesign yaCourseDesign)
    {
        startPage();
        List<YaCourseDesign> list = yaCourseDesignService.selectYaCourseDesignList(yaCourseDesign);
        return getDataTable(list);
    }

    /**
     * 导出课程设计列表
     */
    @RequiresPermissions("teaching:course_design:export")
    @Log(title = "课程设计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YaCourseDesign yaCourseDesign)
    {
        List<YaCourseDesign> list = yaCourseDesignService.selectYaCourseDesignList(yaCourseDesign);
        ExcelUtil<YaCourseDesign> util = new ExcelUtil<YaCourseDesign>(YaCourseDesign.class);
        util.exportExcel(response, list, "课程设计数据");
    }

    /**
     * 获取课程设计详细信息
     */
    @RequiresPermissions("teaching:course_design:query")
    @GetMapping(value = "/{stageId}")
    public AjaxResult getInfo(@PathVariable("stageId") Long stageId)
    {
        return success(yaCourseDesignService.selectYaCourseDesignListByStageId(stageId));
    }

    /**
     * 新增课程设计
     */
    @RequiresPermissions("teaching:course_design:add")
    @Log(title = "课程设计", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YaCourseDesign yaCourseDesign)
    {
        return toAjax(yaCourseDesignService.insertYaCourseDesign(yaCourseDesign));
    }

    /**
     * 修改课程设计
     */
    @RequiresPermissions("teaching:course_design:edit")
    @Log(title = "课程设计", businessType = BusinessType.UPDATE)
    @PutMapping("/{stage}")
    public AjaxResult edit(@PathVariable("stage")Integer stage,@RequestBody List<YaCourseDesign> courseDesignList)
    {
        return toAjax(yaCourseDesignService.updateYaCourseDesign(stage,courseDesignList));
    }

     /**
     * 保存关联面试题
     */
    @RequiresPermissions("teaching:course_design:edit")
    @Log(title = "课程设计", businessType = BusinessType.UPDATE)
    @PutMapping("/related_interview/{cdId}")
    public AjaxResult editRelatedInterview(@PathVariable("cdId")Integer cdId,@RequestBody List<Integer> interviewIdList)
    {
        return toAjax(yaCourseDesignService.editRelatedInterview(cdId,interviewIdList));
    }
    /**
     * 删除课程设计
     */
    @RequiresPermissions("teaching:course_design:remove")
    @Log(title = "课程设计", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(yaCourseDesignService.deleteYaCourseDesignByIds(ids));
    }
}
